#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
int bucket[1000005];

void solve(){
    cin>>n;
    set<int> b;
    memset(bucket,0,sizeof(bucket));
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        bucket[x]++;
        b.insert(x);
    }
    int sum=0;
    for(auto i:b){
        sum+=((bucket[i]-1)*i);
    }
    cout<<sum<<endl;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
